package com.pikaqiu.warehouse.utils;

import cn.hutool.core.util.StrUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @Author: Administrator
 * @Date: 2024/7/23
 */
public class StringUtils extends StrUtil {

    /**
     * 将金额转换为2位小数的字符串
     */
    public static String money2String(BigDecimal money) {
        return money2String(money, 2);
    }

    /**
     * 将金额转换为2位小数的字符串
     */
    public static String money2String(BigDecimal money, Integer newScale) {
        return money.setScale(newScale, RoundingMode.HALF_UP).toString();
    }

    /**
     * 脱敏手机号
     */
    public static String desensitizePhone(String phone) {
        return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
    }

    /**
     * 脱敏姓名
     */
    public static String desensitizeName(String name) {
        return name.replaceAll("([\\u4e00-\\u9fa5]{1})(.*)", "$1**");
    }

    /**
     * 脱敏地址
     */
    public static String desensitizeAddress(String address) {
        return address.replaceAll("([\\u4e00-\\u9fa5]{1})(.*)", "$1**");
    }


}
